package haitao.numberpicker.city;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.example.city2.R;

import org.haitao.common.utils.TimeUtil;

import java.util.Date;

import haitao.picker.datepicker.AlertDatePicker;
import haitao.picker.datepicker.DatePicker;

public class MainActivity extends Activity {


	private Button showdate_btn;
	private AlertDatePicker alertDatePicker;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		showdate_btn =findViewById(R.id.showdate_btn);

		showdate_btn.setOnClickListener( new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				if (alertDatePicker==null || !alertDatePicker.isShowing())
				     alertDatePicker=	new AlertDatePicker.Builder(MainActivity.this)
						.setOnDateSelectedListener(new DatePicker.OnDateSelectedListener() {
							@Override
							public void onDateSelected(Date selectDate, String selectDateStr) {
								Toast.makeText(getApplicationContext()
										,selectDateStr
										,Toast.LENGTH_SHORT).show();
							}
						})
						.setTitle("时间") // 不设置 则没有标题
						.setCancelable(false)
						//.setDate(TimeUtil.getDateBefore(new Date(),365*3),new Date(),TimeUtil.getDateBefore(new Date(),1)).
						//.setDate(new Date(),TimeUtil.getDateAfter(new Date(),7)).
//						.setDate(TimeUtil.stringToDate("2018-05-29",TimeUtil.FORMAT_DATE),
//								TimeUtil.stringToDate("2018-05-31",TimeUtil.FORMAT_DATE),
//								TimeUtil.stringToDate("2018-05-29 ",TimeUtil.FORMAT_DATE))
						.setDate(TimeUtil.stringToDate("2018-05-30 11:20",TimeUtil.FORMAT_DATE_TIME),
								TimeUtil.stringToDate("2018-06-06 11:20",TimeUtil.FORMAT_DATE_TIME),
								TimeUtil.stringToDate("2018-05-31 12:40",TimeUtil.FORMAT_DATE_TIME))
							 .showTime(true)
							 .showCancel(true)
//							 .showHitText(false)
							 .show();
			}
		});


	}

}
